package com.ddwl.goods.controller;


import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.goods.service.TopicService;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.bo.goods.ItemTopicBo;
import com.ddwl.schema.bo.goods.ItemTopicSortBo;
import com.ddwl.schema.bo.goods.TopicBo;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.goods.TopicVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("topic")
@Api(tags = "专题服务")
public class TopicController extends BaseController {
    @Autowired
    private TopicService topicService;

    @PostMapping("create")
    @ApiOperation("创建或更新专题")
    public RestVo<TopicVo> create(@Valid @RequestBody TopicBo topicBo) {
        return RestVo.ok(topicService.create(topicBo));
    }

    @PostMapping("list")
    @ApiOperation("专题列表")
    public RestVo<PageVo<TopicVo>> list(@RequestBody PageBo<TopicBo> topicBoPageBo){
        return RestVo.ok(topicService.list(topicBoPageBo));
    }

    @PostMapping("addItem")
    @ApiOperation("绑定商品")
    public RestVo<Integer> addItem(@Valid @RequestBody ItemTopicBo topicBo){
        return RestVo.ok(topicService.addItem(topicBo));

    }

    @PostMapping("topicItemSort")
    @ApiOperation("专题商品排序")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo topicItemSort(@RequestBody ItemTopicSortBo itemTopicSortBo){
        topicService.topicItemSort(itemTopicSortBo);
        return RestVo.ok();
    }

    @DeleteMapping("del/{id}")
    @ApiOperation("删除专题")
    public RestVo<Integer> delete(@PathVariable("id")String id){
        return RestVo.ok(topicService.delete(id));
    }

}
